/**
 * API接口统一管理
 * 将所有接口按模块分类，便于维护和管理
 */

import request from '@/utils/request'

// 用户相关接口
export const userApi = {
  // 用户登录
  login(data) {
    return request.post('/v1/auth/login', data)
  },
  
  // 用户注册
  register(data) {
    return request.post('/v1/auth/register', data)
  },
  
  // 获取用户信息
  getUserInfo() {
    return request.get('/v1/user/info')
  },
  
  // 更新用户信息
  updateUserInfo(data) {
    return request.put('/v1/user/info', data)
  },
  
  // 修改密码
  changePassword(data) {
    return request.post('/v1/user/change-password', data)
  },
  
  // 用户登出
  logout() {
    return request.post('/v1/auth/logout')
  },
  
  // 刷新token
  refreshToken() {
    return request.post('/v1/auth/refresh-token')
  }
}

// 习惯管理相关接口
export const habitsApi = {
  // 获取习惯列表
  getHabitsList(params = {}) {
    return request.get('/v1/habits', params)
  },
  
  // 创建习惯
  createHabit(data) {
    return request.post('/v1/habits', data)
  },
  
  // 更新习惯
  updateHabit(id, data) {
    return request.put(`/v1/habits/${id}`, data)
  },
  
  // 删除习惯
  deleteHabit(id) {
    return request.delete(`/v1/habits/${id}`)
  },
  
  // 获取习惯详情
  getHabitDetail(id) {
    return request.get(`/v1/habits/${id}`)
  },
  
  // 标记习惯完成
  markHabitComplete(id, data) {
    return request.post(`/v1/habits/${id}/complete`, data)
  },
  
  // 取消习惯完成
  unmarkHabitComplete(id, data) {
    return request.post(`/v1/habits/${id}/uncomplete`, data)
  },
  
  // 获取习惯统计数据
  getHabitStats(id, params = {}) {
    return request.get(`/v1/habits/${id}/stats`, params)
  },
  
  // 获取习惯历史记录
  getHabitHistory(id, params = {}) {
    return request.get(`/v1/habits/${id}/history`, params)
  }
}

// 财务管理相关接口
export const financeApi = {
  // 获取账户列表
  getAccounts(params = {}) {
    return request.get('/v1/finance/accounts', params)
  },
  
  // 创建账户
  createAccount(data) {
    return request.post('/v1/finance/accounts', data)
  },
  
  // 更新账户
  updateAccount(id, data) {
    return request.put(`/v1/finance/accounts/${id}`, data)
  },
  
  // 删除账户
  deleteAccount(id) {
    return request.delete(`/v1/finance/accounts/${id}`)
  },
  
  // 获取交易记录
  getTransactions(params = {}) {
    return request.get('/v1/finance/transactions', params)
  },
  
  // 创建交易记录
  createTransaction(data) {
    return request.post('/v1/finance/transactions', data)
  },
  
  // 更新交易记录
  updateTransaction(id, data) {
    return request.put(`/v1/finance/transactions/${id}`, data)
  },
  
  // 删除交易记录
  deleteTransaction(id) {
    return request.delete(`/v1/finance/transactions/${id}`)
  },
  
  // 获取预算列表
  getBudgets(params = {}) {
    return request.get('/v1/finance/budgets', params)
  },
  
  // 创建预算
  createBudget(data) {
    return request.post('/v1/finance/budgets', data)
  },
  
  // 更新预算
  updateBudget(id, data) {
    return request.put(`/v1/finance/budgets/${id}`, data)
  },
  
  // 删除预算
  deleteBudget(id) {
    return request.delete(`/v1/finance/budgets/${id}`)
  },
  
  // 获取财务统计
  getFinanceStats(params = {}) {
    return request.get('/v1/finance/stats', params)
  },
  
  // 获取收支分析
  getIncomeExpenseAnalysis(params = {}) {
    return request.get('/v1/finance/analysis/income-expense', params)
  },
  
  // 获取资产负债分析
  getAssetLiabilityAnalysis(params = {}) {
    return request.get('/v1/finance/analysis/asset-liability', params)
  }
}

// 时间管理相关接口
export const timeApi = {
  // 获取时间记录
  getTimeRecords(params = {}) {
    return request.get('/v1/time/records', params)
  },
  
  // 创建时间记录
  createTimeRecord(data) {
    return request.post('/v1/time/records', data)
  },
  
  // 更新时间记录
  updateTimeRecord(id, data) {
    return request.put(`/v1/time/records/${id}`, data)
  },
  
  // 删除时间记录
  deleteTimeRecord(id) {
    return request.delete(`/v1/time/records/${id}`)
  },
  
  // 开始计时
  startTimer(data) {
    return request.post('/v1/time/timer/start', data)
  },
  
  // 停止计时
  stopTimer(id) {
    return request.post(`/v1/time/timer/${id}/stop`)
  },
  
  // 暂停计时
  pauseTimer(id) {
    return request.post(`/v1/time/timer/${id}/pause`)
  },
  
  // 恢复计时
  resumeTimer(id) {
    return request.post(`/v1/time/timer/${id}/resume`)
  },
  
  // 获取活动分类
  getActivityCategories() {
    return request.get('/v1/time/categories')
  },
  
  // 创建活动分类
  createActivityCategory(data) {
    return request.post('/v1/time/categories', data)
  },
  
  // 更新活动分类
  updateActivityCategory(id, data) {
    return request.put(`/v1/time/categories/${id}`, data)
  },
  
  // 删除活动分类
  deleteActivityCategory(id) {
    return request.delete(`/v1/time/categories/${id}`)
  },
  
  // 获取时间统计
  getTimeStats(params = {}) {
    return request.get('/v1/time/stats', params)
  },
  
  // 获取时间分布分析
  getTimeDistributionAnalysis(params = {}) {
    return request.get('/v1/time/analysis/distribution', params)
  }
}

// 待办事项相关接口
export const todosApi = {
  // 获取待办列表
  getTodosList(params = {}) {
    return request.get('/v1/todos', params)
  },
  
  // 创建待办事项
  createTodo(data) {
    return request.post('/v1/todos', data)
  },
  
  // 更新待办事项
  updateTodo(id, data) {
    return request.put(`/v1/todos/${id}`, data)
  },
  
  // 删除待办事项
  deleteTodo(id) {
    return request.delete(`/v1/todos/${id}`)
  },
  
  // 标记待办完成
  markTodoComplete(id) {
    return request.post(`/v1/todos/${id}/complete`)
  },
  
  // 取消待办完成
  unmarkTodoComplete(id) {
    return request.post(`/v1/todos/${id}/uncomplete`)
  },
  
  // 获取待办分类
  getTodoCategories() {
    return request.get('/v1/todos/categories')
  },
  
  // 创建待办分类
  createTodoCategory(data) {
    return request.post('/v1/todos/categories', data)
  },
  
  // 更新待办分类
  updateTodoCategory(id, data) {
    return request.put(`/v1/todos/categories/${id}`, data)
  },
  
  // 删除待办分类
  deleteTodoCategory(id) {
    return request.delete(`/v1/todos/categories/${id}`)
  },
  
  // 获取待办统计
  getTodoStats(params = {}) {
    return request.get('/v1/todos/stats', params)
  }
}

// 统计分析相关接口
export const statsApi = {
  // 获取综合统计数据
  getOverallStats(params = {}) {
    return request.get('/v1/stats/overall', params)
  },
  
  // 获取习惯趋势数据
  getHabitsTrend(params = {}) {
    return request.get('/v1/stats/habits/trend', params)
  },
  
  // 获取财务趋势数据
  getFinanceTrend(params = {}) {
    return request.get('/v1/stats/finance/trend', params)
  },
  
  // 获取时间分布数据
  getTimeDistribution(params = {}) {
    return request.get('/v1/stats/time/distribution', params)
  },
  
  // 获取效率分析数据
  getProductivityAnalysis(params = {}) {
    return request.get('/v1/stats/productivity', params)
  },
  
  // 获取目标完成情况
  getGoalProgress(params = {}) {
    return request.get('/v1/stats/goals/progress', params)
  },
  
  // 导出统计报告
  exportStatsReport(params = {}) {
    return request.get('/v1/stats/export', params)
  }
}

// 设置相关接口
export const settingsApi = {
  // 获取用户设置
  getUserSettings() {
    return request.get('/v1/settings/user')
  },
  
  // 更新用户设置
  updateUserSettings(data) {
    return request.put('/v1/settings/user', data)
  },
  
  // 获取通知设置
  getNotificationSettings() {
    return request.get('/v1/settings/notifications')
  },
  
  // 更新通知设置
  updateNotificationSettings(data) {
    return request.put('/v1/settings/notifications', data)
  },
  
  // 获取隐私设置
  getPrivacySettings() {
    return request.get('/v1/settings/privacy')
  },
  
  // 更新隐私设置
  updatePrivacySettings(data) {
    return request.put('/v1/settings/privacy', data)
  },
  
  // 数据备份
  backupData() {
    return request.post('/v1/settings/backup')
  },
  
  // 数据恢复
  restoreData(data) {
    return request.post('/v1/settings/restore', data)
  },
  
  // 清除数据
  clearData() {
    return request.post('/v1/settings/clear-data')
  }
}

// 文件上传相关接口
export const uploadApi = {
  // 上传头像
  uploadAvatar(filePath) {
    return request.upload('/v1/upload/avatar', filePath)
  },
  
  // 上传图片
  uploadImage(filePath, formData = {}) {
    return request.upload('/v1/upload/image', filePath, formData)
  },
  
  // 上传文件
  uploadFile(filePath, formData = {}) {
    return request.upload('/v1/upload/file', filePath, formData)
  },
  
  // 删除文件
  deleteFile(fileId) {
    return request.delete(`/v1/upload/file/${fileId}`)
  }
}

// 导出所有API
export default {
  user: userApi,
  habits: habitsApi,
  finance: financeApi,
  time: timeApi,
  todos: todosApi,
  stats: statsApi,
  settings: settingsApi,
  upload: uploadApi
}

// 单独导出各模块API，方便按需引入
export {
  // userApi,
  // habitsApi,
  // financeApi,
  // timeApi,
  // todosApi,
  // statsApi,
  // settingsApi,
  // uploadApi
}